import numpy as np
import matplotlib.pyplot as plt

paths = ['mars_1bar','mars_500mbar','mars_200mbar','mars_1.3bar','mars_800mbar']
flux = ['0','1e10','1e10','1e11','1e12','2e12']
flux2= ['1e9','1e10','1e11','3e11']
names = ['Tprofile_MARS-1000mbar-','Tprofile_MARS-500mbar-','Tprofile_MARS-200mbar-',\
         'Tprofile_MARS-1000mbar-','Tprofile_MARS-500mbar-']
iy = [0,1,2,0,1,2]
ix = [0,0,0,1,1,1]

#clr = ['red','orange','green','blue','grey']
#clr = ['grey','blue','green','orange','red']
clr = ['blue','green','purple','magenta','red','orange']
lns = ['-','--','-.',':']
lw = 2.0

fig,ax=plt.subplots(ncols=3,nrows=2,figsize=(9,6))

fctr = 0
for i in paths: 
    used = [] # check if color & lns has been used in a panel yet

    # select a flux range
    '''if '200' in i:
        fluxes = ['1e7','1e8','2e8']
    elif '500' in i:
        fluxes = ['1e7','1e8','5e8']
    elif '1bar' in i:
    fluxes = ['1e7','1e8','1e9']'''
    if '200' in i:
        fluxes = flux2
    else:
        fluxes = flux

    jctr = 0
    for j in fluxes:
        
        # open file
        if (not '800' in i) and (not '1.3' in i):
            infile = open(i+'/'+names[fctr]+j+'H2-s075.dat','r')
        else:
            infile = open(i+'/'+names[fctr]+j+'H2-300mbarN2-s075.dat','r')
        
        # read data
        temp = infile.readline().split()
        temp = infile.readline().split()
        p,z,t = [],[],[]
        while len(temp)>1:
            p += [float(temp[0])]
            z += [float(temp[1])]
            t += [float(temp[2])]
            temp = infile.readline().split()
        
        # select color & lns
        '''if fctr == 2:
            plns = ':'
        if fctr == 0:
            plns = '--'
        if fctr == 1:
            plns = '--'
        if fctr == 3:
            plns = '-'
        if fctr == 4:
            plns = '-'''
        plns = '-'
            
        ax[ix[fctr],iy[fctr]].semilogy(t,p,color=clr[jctr],linestyle=plns,linewidth=lw,label=flux)
        ax[ix[fctr],iy[fctr]].set_title(i)
        ax[ix[fctr],iy[fctr]].set_ylim([2,1e-7])
        jctr += 1

    fctr += 1
plt.savefig('tp.png',dpi=300)
